/*
 * @Description: 
 * @Author: yeeChen
 * @Date: 2022-12-16 16:42:09
 * @LastEditTime: 2022-12-16 16:49:18
 * @LastEditors: yeeChen
 */
// 1.创建http模块
const http = require('http')

// 2.创建http服务器
const serve = http.createServer()

// 3.为服务器添加request请求，来监听服务器请求
serve.on('request', function (req, res) {
    const url = req.url
    let content = '<h1>404 Not found</h1>'
    if (url === '/' || url === '/index.html') {
        content = '<h1>首页</h1>'
    } else if (url === '/about.html') {
        content = '<h1>关于</h1>'
    } else {
        
    }
    // 解决中文乱码问题
    res.setHeader('Content-Type', 'text/html;charset=utf-8')
    res.end(content)
})

// 4.启动服务器
serve.listen(8080, () => {
    console.log('Your running at http://127.0.0.1:8080');
})